import React, { Component } from 'react'
import axios from 'axios';
import qs from 'querystring';
export default class HeroDetail extends Component {
    state = {
        hero: {}
    }
    render () {
        return (
            <div>
                <img width="100%" src={"http://127.0.0.1:3002" + this.state.hero.big_image} alt="" />
            </div>
        )
    }

    async componentDidMount () {
        console.log(this.props);
        //获取 id  params 方式
        // let id = this.props.match.params.id;
        //获取 id  query 方式
        // console.log(this.props);
        // let searchStr = this.props.location.search.slice(1);///  ?id=6  => id=6
        // let tmp = qs.parse(searchStr);
        // let id = tmp.id;
        //获取 id   state 方法
        let id = this.props.location.state.id;

        //根据 id 发送 AJAX 请求
        let result = await axios('http://127.0.0.1:3002/heros/' + id);
        this.setState({
            hero: result.data
        })
    }
}
